home *** CD-ROM | disk | FTP | other *** search
-
- /***********************************************************************/
-
- /* File KSAUX.C - S4 Drivers for Nimbus Piconet; interface from
- Kermit calls to Mike Maloney standard interface for RS422 mode.
- Chris Kennington 1st July 1985 */
-
- /* All procedures in this file map down into calls to the functions
- described In Mike Maloney's "Nimbus Piconet interface
- specification" of 1st July 1985.
- 422 mode uses piconet address 1fH. */
-
- #define PIC422 0x1f
-
- extern int p_break(), p_close(), p_flush(), p_getc(), p_open(),
- p_putc(), p_speed(), p_status(), p_xonxoff(); /* MikeM procs */
-
- static int status;
- static char alive = 0; /* initialized flag */
- static char awake = 0; /* awake flag */
- static char parity = 0;
- static char speed = 1;
- static int picspeed[] = {110,300,600,1200,2400,4800,9600,19200,0};
- /* all valid speeds: 0 1 2 3 4 5 6 7 */
- static char partab[] = {
- /* character-parity table, 7-bit chars; 0 if even, 1 if odd. */
- 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 0-15, 00-0f */
- 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1, /* 16-31, 10-1f */
- 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1, /* 32-47, 20-2f */
- 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 48-63, 30-3f */
- 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1, /* 64-79, 40-4f */
- 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 80-95, 50-5f */
- 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 96-111, 60-6f */
- 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1 /* 112-127, 70-7f */
- }; /* end of parity table */
-
-
-
- char par(c,p) /* return with parity */
- /* strips to 7 bits, then adds correct parity; even if p=0, else odd */
- char c, p;
- {
- char b, d;
-
- c &= 0x7f;
- b = (partab[c] == 0) ? 0 : 0x80;
- if (p != 0)
- b ^= 0x80;
- d = b | c;
- return(d);
- } /* end of par() */
-
-
-
- s4break(len) /* send break - official */
- char len;
- {
- int time;
-
- if ( (alive == 0) || (awake == 0) ) {
- printf(" not in contact ");
- return(-1);
- }
- time = len << 7; /* sec/8 => msec */
- p_break(PIC422,time);
- outc(' ');
- return(0);
- } /* end of s4break() */
-
-
- s4env() /* return environment value */
- /* Environment codes are:-
- 0 - 480Z, via SIO4; 1 - 480Z, via IDC;
- 2 - Nimbus, via DCC; 3 - Nimbus, via RS422 Aux;
- 4 - Nimbus, via Piconet SIM;
- 5 - either, via Network Comms Server (n.y.i.).
- (see KDATA.C for texts used on bottom header) */
- {
- return(3);
- } /* end of s4env() */
-
-
- s4get(n,buff) /* read some character, maybe */
- char n, *buff;
- {
- awake = 1;
- if ( (p_getc(PIC422,buff)) != 0 )
- return(0);
- else
- return(1);
- } /* end of s4get() */
-
-
- s4get7(n,buff) /* read some 7-character, maybe */
- char n, *buff;
- {
- awake = 1;
- if ( (p_getc(PIC422,buff)) != 0 )
- return(0);
- else {
- *buff &= 0x7f;
- return(1);
- }
- } /* end of s4get7() */
-
-
- s4go() /* fire up RS422 comms */
- {
- int i;
- char *addr;
-
- awake = 1;
- if (alive != 0)
- return(0);
- if ( (addr = malloc (1610)) == 0 ) {
- printf("\nNo store for comms.\n");
- kermkill(1);
- }
- else {
- if ( (i = p_open(PIC422,'I',1600,addr)) != 0 ) {
- printf("\nCannot open comms, error-code %xx.\n",i);
- kermkill(1);
- }
- alive = 1;
- }
- return(0);
- } /* end of s4go() */
-
-
- s4put(n,buff) /* send some chars */
- char n, *buff;
- {
- char c;
-
- awake = 1;
- c = *buff;
- switch(parity) {
- default: /* 0 or > 3 (impossible) */
- break;
- case 1: /* 1 = odd */
- c = par(c,1);
- break;
- case 2: /* 2 = even */
- c = par(c,0);
- break;
- case 3: /* 3 = mark */
- c |= 0x80;
- break;
- } /* end switch */
- if (p_putc(PIC422,c) == 0)
- return(1);
- else
- return(0);
- } /* end of s4put */
-
-
- s4set(facil,wr5) /* set facilities - dummy */
- int facil;
- char wr5;
- {
- char x;
-
- parity = (facil & 0x0300) >> 8;
- x = ( (facil & 0x0002) == 0 ) ? 0 : 0xff;
- p_xonxoff(PIC422,x);
- return(0);
- } /* end of s4set() */
-
-
- s4sleep() /* dummy deactivate */
- {
- awake = 0;
- return(0);
- }
-
-
- s4speed(kspeed) /* set line-speed */
- char kspeed; /* 480Z speed-code */
- {
- int i, spd;
-
- speed = kspeed;
- if (alive != 0) {
- spd = picspeed[kspeed];
- if ( (i = p_speed(PIC422,spd,spd)) != 0 ) {
- printf("\nCannot set speed, error-code %xx.\n",i);
- kermkill(1);
- } }
- return(0);
- } /* end of s4speed() */
-
-
- s4status() /* return status-byte (in int) */
- {
- return(p_status(PIC422));
- } /* end of s4status() */
-
-
- s4stop() /* close down communications */
- {
- if (alive = 0)
- return(0);
- alive = awake = 0;
- p_close(PIC422);
- return(0);
- } /* end of s4stop() */
-
-
-
- s4test() /* return status - dummy */
- {
- return(0);
- } /* end of s4test() */
-
-
- /****************** END of file KSMIKE.C *******************************/